package com.pf.controller;

import com.pf.aop.DecryptMethod;
import com.pf.dto.User;
import org.springframework.web.bind.annotation.*;

/**
 * @author PanFei
 * @date 2021/9/9
 * @Version 1.0
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    /**
     * 测试 账号密码前端加密，后端解密。
     * 需求：
     * 前端通过AES将账号和密码加密，然后将AES密钥通过RSA的公钥加密。最终前端将加密后的账号密码以及密钥传给后端。
     * 后端先解密前端传递的RSA公钥加密的AES密钥，然后再用解密的AES密钥解密账号和密码信息
     * <p>
     * 测试入参：参数可通过 AesAndRsaUtils.encryptByWeb()方法模拟
     * {
     * "secretKey":"VL9CaIVVj+hll2QWQZSTf/Jqd6tir4zlRPfx3kR+047rbGN2Y5k1s8LM81+rPKcQd96DCybVcL6uLw6VgVEDhupW80yryTtHnEeiqk8qvdnFGCaT06b59yfzjZ3x3n8ZeD8rZi8dEgQ+xOxJtx+PmWPqoCPqvVYxmoF0tDxztz7tBoD+Z+22iZIS0wRRd4Ac3ubolVt5ChgaaudEBOn++ATQGx5k0E5vdiWYDssIM31hWVz+3gLYQ2xlAv3qaUlZNhnDFItLN1ZWoqzjB+zYqU8P4Q6hCdisalNC+RcuWMijnN+mk7YJPKM3ehMg6JPgy3wFO6qKf242smTJetOjFA==",
     * "account":"VIb574NaGB90jHP22eMp0w==",
     * "password":"Drf9QbNyLdPHbUXURxB5gw==",
     * "address":"上海市"
     * }
     * <p>
     * 解密后：
     * {
     * "secretKey": "VL9CaIVVj+hll2QWQZSTf/Jqd6tir4zlRPfx3kR+047rbGN2Y5k1s8LM81+rPKcQd96DCybVcL6uLw6VgVEDhupW80yryTtHnEeiqk8qvdnFGCaT06b59yfzjZ3x3n8ZeD8rZi8dEgQ+xOxJtx+PmWPqoCPqvVYxmoF0tDxztz7tBoD+Z+22iZIS0wRRd4Ac3ubolVt5ChgaaudEBOn++ATQGx5k0E5vdiWYDssIM31hWVz+3gLYQ2xlAv3qaUlZNhnDFItLN1ZWoqzjB+zYqU8P4Q6hCdisalNC+RcuWMijnN+mk7YJPKM3ehMg6JPgy3wFO6qKf242smTJetOjFA==",
     * "account": "18221177062",
     * "password": "abc123",
     * "address": "上海市"
     * }
     *
     * @param user
     * @return
     */
    @PostMapping("/decrypt")
    @DecryptMethod
    public User decrypt(@RequestBody User user) {
        return user;
    }


    /**
     * 测试非 application/json 请求测试（本案例不支持这种方式）
     *
     * @param user
     * @return
     */
    @PostMapping("/decrypt2")
    @DecryptMethod
    public User decrypt2(User user) {
        return user;
    }

    /**
     * get请求（本案例不支持这种方式）
     *
     * @param account
     * @param password
     * @param address
     * @return
     */
    @GetMapping("/decrypt3")
    @DecryptMethod
    public User decrypt3(String account, String password, String address) {
        User user = new User();
        user.setAccount(account);
        user.setPassword(password);
        user.setAddress(address);
        return user;
    }
}
